package edu.uta.cfl.GUI;
/**
 * This class is used to read the input from the user
 * Also perform validation check to ensure
 * the user had entered all the necessary information.
 * @author jagan
 */
import java.util.ArrayList;

import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

public class GetResultsFromUser {
	
	JTable table;
	ArrayList<Integer> results = new ArrayList<Integer>();
	
	public GetResultsFromUser(JTable table) {
		super();
		this.table = table;
	}
	
	public ArrayList<Integer> getResults()
	{
		int index = 0;
		JTableHeader th = table.getTableHeader();  
	    TableColumnModel tcm = th.getColumnModel();  
	    for(int x = 0, y = tcm.getColumnCount(); x < y; x++)  
	     {  
	         TableColumn tc = tcm.getColumn(x);  
	        // System.out.println("Column name = "+tc.getHeaderValue()+", width = "+tc.getWidth()+" Model Index"+tc.getModelIndex());  
	         if(tc.getHeaderValue() == "Results")
	         {
	        	 index = tc.getModelIndex();
	         }
	      } 
	   
	    for(int i=0;i<table.getRowCount();i++)
		{
			System.out.println(table.getModel().getValueAt(i, index));
			if(table.getModel().getValueAt(i, index).toString().trim().equalsIgnoreCase("Pass"))
			{
				results.add(1);
			}
			else if(table.getModel().getValueAt(i,index).toString().trim().equalsIgnoreCase("Fail"))
			{
				results.add(0);
			}
			
		}
	  
	    return results;
	}

}
